package com.bang.itstack.day18;

import com.bang.itstack.day18.listener.EventManager;
import com.bang.itstack.day18.listener.MQEventListener;
import com.bang.itstack.day18.listener.MessageEventListener;

/**
 * @ClassName: LotteryService
 * @Desc: TODO
 * @author: <Bang>
 * @Date: 2021/10/23 18:27
 * @Version: 1.0
 * @Modified By:
 */
public  abstract class LotteryService {

    private EventManager eventManager;

    public LotteryService() {
        eventManager = new EventManager(EventManager.EventType.MQ, EventManager.EventType.Message);
        eventManager.subscribe(EventManager.EventType.MQ, new MQEventListener());
        eventManager.subscribe(EventManager.EventType.Message, new MessageEventListener());
    }

    public LotteryResult draw(String uId) {
        LotteryResult lotteryResult = doDraw(uId);
        // 需要什么通知就给调用什么方法
        eventManager.notify(EventManager.EventType.MQ, lotteryResult);
        eventManager.notify(EventManager.EventType.Message, lotteryResult);
        return lotteryResult;
    }

    protected abstract LotteryResult doDraw(String uId);
}
